//
//  MainViewController.m
//  TP
//
//  Created by apple on 16/3/10.
//  Copyright © 2016年 姜小琦. All rights reserved.
//

#import "MainViewController.h"
#import "tabbarView.h"
#import "HomePageViewController.h"
#import "HuanKuanPageViewController.h"
#import "ZhangBenPageViewController.h"
#import "MyPageViewController.h"
#import "NewMingXinViewController.h"
#import "JTCSM.h"
#import "JTCSMSingle.h"
#define SELECTED_VIEW_CONTROLLER_TAG 98456345

#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
@interface MainViewController ()<tabbarDelegate,UIAlertViewDelegate,HidomePageViewControllerDelegate>
{
    CGFloat orginHeight;
    CGFloat orginWidth;
    NSInteger number;
    NSMutableDictionary         *m_UserdicInfo;
}

@end

@implementation MainViewController


static MainViewController* _sharedMainView;

+(MainViewController *)shareMainViewController{
    if(!_sharedMainView)
    {
        _sharedMainView = [[self alloc]init];
    }
    return _sharedMainView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor blackColor]];
    self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [UIColor clearColor];
    orginWidth = self.view.frame.size.width;
    orginHeight = self.view.frame.size.height;
    _tabbar = [[tabbarView alloc]initWithFrame:CGRectMake(0, orginHeight-49, orginWidth, 49)];
    _tabbar.backgroundColor = RGBACOLOR(241, 242, 244, 1);
    _tabbar.delegate = self;
    [self.view addSubview:_tabbar];
    _arrayViewcontrollers = [self getViewcontrollers];
    [self touchBtnAtIndex:0];
   [JTCSMSingle shareSingle].tarbarID = 0;
  
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(remonvTarBar) name:@"remonvTarBar" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gotomyPageVC) name:@"gotomyPageVC" object:nil];
   
    
}
- (void)gotomyPageVC{
    
    [self touchBtnAtIndex:3];
    [_tabbar btn1Click:_tabbar.button_4];
}

- (void)remonvTarBar{
    if ([JTCSMSingle shareSingle].isRemoveTarbar) {
        [_tabbar removeFromSuperview];
    }else{
        [self.view addSubview:_tabbar];
    }
    
}
-(void)touchBtnAtIndex:(NSInteger)index
{
    
    
    UIView* currentView = [self.view viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];
    [currentView removeFromSuperview];
    NSDictionary* data = [_arrayViewcontrollers objectAtIndex:index];
    UINavigationController *viewController = data[@"viewController"];
    [JTCSMSingle shareSingle].navigationC = viewController;
    viewController.view.tag = SELECTED_VIEW_CONTROLLER_TAG;
    [self.view insertSubview:viewController.view belowSubview:_tabbar];
    
}
-(NSArray *)getViewcontrollers
{
    NSArray* tabBarItems = nil;
    HomePageViewController *investmentPageVC=[[HomePageViewController alloc] init];
    investmentPageVC.nameTitle = @"王者信用卡管家";
    investmentPageVC.delegate = self;
    UINavigationController *investmentPagenav = [[UINavigationController alloc]initWithRootViewController:investmentPageVC];
    [investmentPagenav.navigationBar setBackgroundImage:[df createImageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
    
//    HuanKuanPageViewController *WorkVC=[[HuanKuanPageViewController alloc] init];
//    WorkVC.nameTitle = @"还款";
//    UINavigationController *workNav = [[UINavigationController alloc]initWithRootViewController:WorkVC];
//    [workNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBar2.png"] forBarMetrics:UIBarMetricsDefault];
    NewMingXinViewController *myVC = [[NewMingXinViewController alloc]init];
    myVC.nameTitle = @"收款明细";
    UINavigationController *myNav = [[UINavigationController alloc]initWithRootViewController:myVC];
    [myNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBar2.png"] forBarMetrics:UIBarMetricsDefault];
    MyPageViewController *shopVC = [[MyPageViewController alloc]init];
    shopVC.nameTitle = @"我的";
    UINavigationController *shopNav = [[UINavigationController alloc]initWithRootViewController:shopVC];
    [shopNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBar2.png"] forBarMetrics:UIBarMetricsDefault];
    
    tabBarItems = [NSArray arrayWithObjects:
                   [NSDictionary dictionaryWithObjectsAndKeys:investmentPagenav,
                    @"viewController", nil],
                   [NSDictionary dictionaryWithObjectsAndKeys: myNav,
                    @"viewController", nil],
                   [NSDictionary dictionaryWithObjectsAndKeys:shopNav,
                    @"viewController", nil],nil];
//    [NSDictionary dictionaryWithObjectsAndKeys:workNav,@"viewController", nil],
    return tabBarItems;
    
}

#pragma mark  homepagevcdelegate

- (void)gotoLoginVC{
    [self.mainvcdelegate gotoLoginViewController];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
